package com.piggy.logi.sys.mapper;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.piggy.logi.sys.api.domain.LogiSysUser;
import com.piggy.common.core.web.page.BaseMapperPlus;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 用户表 数据层
 *
 * @author shark
 */
public interface LogiSysUserMapper extends BaseMapperPlus<LogiSysUser> {

    Page<LogiSysUser> selectPageUserList(@Param("page") Page<LogiSysUser> page, @Param("user") LogiSysUser user);

    /**
     * 根据条件分页查询用户列表
     *
     * @param logiSysUser 用户信息
     * @return 用户信息集合信息
     */
    public List<LogiSysUser> selectUserList(LogiSysUser logiSysUser);

	/**
	 * 根据条件分页查询未已配用户角色列表
	 *
	 * @param user 用户信息
	 * @return 用户信息集合信息
	 */
	public Page<LogiSysUser> selectAllocatedList(@Param("page") Page<LogiSysUser> page, @Param("user") LogiSysUser user);

	/**
	 * 根据条件分页查询未分配用户角色列表
	 *
	 * @param user 用户信息
	 * @return 用户信息集合信息
	 */
	public Page<LogiSysUser> selectUnallocatedList(@Param("page") Page<LogiSysUser> page, @Param("user") LogiSysUser user);

	/**
	 * 通过用户名查询用户
	 *
	 * @param userName 用户名
	 * @return 用户对象信息
	 */
	public LogiSysUser selectUserByUserName(String userName);

	/**
	 * 通过用户名查询用户
	 *
	 * @param phone 手机
	 * @return 用户对象信息
	 */
	public LogiSysUser selectUserByPhone(String phone);

	/**
	 * 通过用户名查询用户
	 *
	 * @param phone 手机
	 * @return 用户对象信息
	 */
	public LogiSysUser selectUserByPhoneAndMainDeptId(@Param("phone") String phone,@Param("mainDeptId") String mainDeptId);

	/**
	 * 通过用户名查询用户
	 *
	 * @param phone 手机
	 * @return 用户对象信息
	 */
	public LogiSysUser selectUserByEmail(String phone);

	/**
	 * 通过用户名查询用户
	 *
	 * @param userName 用户名
	 * @return 用户对象信息
	 */
	public LogiSysUser selectUserByUserNameByDept(@Param("userName") String userName, @Param("deptName")String deptName);

	/**
	 * 通过用户名查询用户
	 *
	 * @param phone 手机
	 * @return 用户对象信息
	 */
	public LogiSysUser selectUserByPhoneByDept(@Param("phone") String phone, @Param("deptName") String deptName);

	public LogiSysUser selectUserByPhoneAndRole(@Param("phone") String phone, @Param("roleKey") String roleKey);

	/**
	 * 通过用户名查询用户
	 *
	 * @param email 手机
	 * @return 用户对象信息
	 */
	public LogiSysUser selectUserByEmailByDept(@Param("email") String email, @Param("deptName") String deptName);

    /**
     * 通过用户ID查询用户
     *
     * @param userId 用户ID
     * @return 用户对象信息
     */
    public LogiSysUser selectUserById(Long userId);

	/**
	 *  根据postcode和部门id查询
	 * @param postCode
	 * @param deptId
	 * @return
	 */
	public List<String>selectUserNameByPostCodeAndDeptId(String postCode,Long deptId);


	public int deleteUserRoleByUserId(Long userId);

	default List<LogiSysUser> selectUserByPhones(List<String> phoneNumbers){
		return selectList(Wrappers.<LogiSysUser>lambdaQuery().in(LogiSysUser::getPhonenumber, phoneNumbers));
	}

	public LogiSysUser getPhone(@Param("flag")int flag, @Param("phone")String phone, @Param("mainDept")String mainDept, @Param("roleKey")String roleKey);

	public List<LogiSysUser> getNotifyUser(@Param("userId")Long userId, @Param("postCode")String postCode, @Param("deptIdList")List<Long> deptIdList);

	default List<LogiSysUser> selectUserByIds(List<Long> idList){
		return selectList(Wrappers.<LogiSysUser>lambdaQuery().in(LogiSysUser::getUserId, idList));
	}
}

